﻿using Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project_V1
{
    public partial class Frm_ModVar_Mod : Form
    {
        public Frm_ModVar_Mod()
        {
            InitializeComponent();            
        }

        //重构构造方法,点击修改和双击dgv的一栏都会传值给Frm_ModVar_Mod窗体
        public Frm_ModVar_Mod(Variable_Ads ModVar)
        {           
            InitializeComponent();
            this.var = ModVar;
            this.Load += Frm_ModVar_Mod_Load;
        }

        public Variable_Ads var;

        void Frm_ModVar_Mod_Load(object sender, EventArgs e)
        {
            InitialComboBox();//初始化ComboBox下拉菜单
            GetVariable();//填充TextBox
        }

        private void GetVariable()
        {
            this.txt_VarName.Text = this.var.VarName;
            this.txt_Note.Text = this.var.Note;
            this.cmb_DataType.Text = this.var.DataType;
            this.chk_IsFiling.Checked = this.var.IsFiling == "1" ? true : false;
            this.chk_IsAlarm.Checked = this.var.IsAlarm == "1" ? true : false;
            this.chk_IsReport.Checked = this.var.IsReport == "1" ? true : false;           
        }

        private void InitialComboBox()
        {
            //初始化ComboBox下拉菜单
            this.cmb_DataType.Items.Add("Bool");
            this.cmb_DataType.Items.Add("Signed");
            this.cmb_DataType.Items.Add("Unsigned");
            this.cmb_DataType.Items.Add("Hex");
            this.cmb_DataType.Items.Add("Long");
            this.cmb_DataType.Items.Add("Long Inverse");
            this.cmb_DataType.Items.Add("Float");
            this.cmb_DataType.Items.Add("Float Inverse");
            this.cmb_DataType.Items.Add("Double");
            this.cmb_DataType.Items.Add("Double Inverse");
            this.cmb_DataType.SelectedIndex = 6;
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            var = new Variable_Ads();
            var.VarName = this.txt_VarName.Text.Trim();
            var.DataType = this.cmb_DataType.Text.Trim();
            var.IsFiling = this.chk_IsFiling.Checked ? "1" : "0";
            var.IsAlarm = this.chk_IsAlarm.Checked ? "1" : "0";
            var.IsReport = this.chk_IsReport.Checked ? "1" : "0";
            var.Note = this.txt_Note.Text.Trim();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
